<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
      :default-sort="{prop: 'date', order: 'desce nding'}"
    >
      <el-table-column align="center" prop="id" label="ID" width="40">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column width="120px" prop="upload_day" align="center" label="上传日期">
        <template slot-scope="scope">
          <span>{{ scope.row.upload_day | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column
        min-width="150px"
        prop="today_daily"
        label="今日处理"
        :show-overflow-tooltip="true"
        align="center"
      >
        <!-- <template slot-scope="{row}">
          <router-link :to="'/example/edit/'+row.id" class="link-type">
            <span>{{ row.today_daily }}</span>
          </router-link>
        </template>-->
      </el-table-column>
      <el-table-column
        min-width="150px"
        label="明日计划"
        prop="tomorrow_daily"
        :show-overflow-tooltip="true"
        align="center"
      >
        <!-- <template slot-scope="{row}">
          <router-link :to="'/example/edit/'+row.id" class="link-type">
            <span>{{ row.title }}</span>
          </router-link>
        </template>-->
      </el-table-column>
      <el-table-column
        min-width="100px"
        label="其他说明"
        prop="other_state"
        :show-overflow-tooltip="true"
        align="center"
      >
        <!-- <template slot-scope="{row}">
          <router-link :to="'/example/edit/'+row.id" class="link-type">
            <span>{{ row.title }}</span>
          </router-link>
        </template>-->
      </el-table-column>
      <el-table-column
        width="100px"
        label="附件"
        :show-overflow-tooltip="true"
        prop="accessory"
        align="center"
      >
        <!-- <template slot-scope="scope">
          <svg-icon
            v-for="n in +scope.row.importance"
            :key="n"
            icon-class="star"
            class="meta-item__icon"
          />
        </template>-->
      </el-table-column>

      <el-table-column width="80px" align="center" prop="add_preson" label="作者">
        <!-- <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>-->
      </el-table-column>

      <el-table-column class-name="status-col" prop="receiver_person" label="收件人" width="80">
        <!-- <template slot-scope="{row}">
          <el-tag :type="row.status | statusFilter">{{ row.status }}</el-tag>
        </template>-->
      </el-table-column>

      <el-table-column class-name="status-col" prop="integral" label="积分" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.integral===null || scope.row.integral==='' || scope.row.integral==='0'" style="color:red">未打分</span>
          <span v-else>{{ scope.row.integral }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="100">
        <template slot-scope="scope">
          <router-link :to="'/example/edit/'+scope.row.id">
            <el-button type="primary" size="small" icon="el-icon-edit">编辑</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination">
      <el-pagination
        ref="pager1"
        background
        :current-page="pageIndex"
        :page-size="pageSize"
        :total="total"
        layout="prev, pager, next"
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
      />
    </div>
  </div>
</template>

<script>
import { getList, getListPage } from '@/api/article'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'ArticleList',
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: [],
      total: 0,
      pageIndex: 1,
      pageSize: 2,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  created() {
    this.getListInfo()
  },
  mounted() {
    setTimeout(() => {
      this.listLoading = false
    }, 1000)
  },
  methods: {
    // 下一页
    sizeChangeHandle: function(size) {
      this.pagesize = size
      // this.selectUserInfo();
      // console.log("size" + this.pageSize);
    },
    currentChangeHandle: function(val) {
      // this.pageIndex = val;
      // // this.selectUserInfo();
      // console.log("index" + this.pageIndex);
      return new Promise((resolve, reject) => {
        getListPage(val).then((response) => {
          this.list = response.data.data
        })
      })
    },

    getListInfo() {
      return new Promise((resolve, reject) => {
        getList().then((response) => {
          this.list = response.data.data
          // console.log("数据");
          // console.log(this.list);
          // console.log(response.data);
          this.total = response.data.total
          this.pageSize = response.data.to
        })
      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
